<html>
<head><meta charset="utf-8"><title>Replacing function calls for certain types · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Replacing.20function.20calls.20for.20certain.20types.html">Replacing function calls for certain types</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="235994694"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Replacing%20function%20calls%20for%20certain%20types/near/235994694" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> firecubez <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Replacing.20function.20calls.20for.20certain.20types.html#235994694">(Apr 24 2021 at 18:45)</a>:</h4>
<p>Hey, I'm trying to do some FFI between C++ and Rust. The C++ library is very complicated: it has virtuals etc which no current tool can translate. So my idea was that I could find each method call on the external types and replace it directly with a call to a wrapper:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="kd">let</span><span class="w"> </span><span class="n">x</span>: <span class="nc">CppType</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">..</span><span class="p">.;</span><span class="w"></span>
<span class="n">x</span><span class="p">.</span><span class="n">test</span><span class="p">();</span><span class="w"></span>
</code></pre></div>
<p>The rustc driver/something would find the x.test() call, realize x is a CppType, and replace that line with something like <code>autogenerated_12345(&amp;mut x);</code> (where <code>autogenerated_12345</code> would be implemented via C++ code and linked in)</p>
<p>The <code>test</code> function wouldnt actually exist on <code>CppType</code> since thats the entire point. If I could generate all the function signatures manually or automatically then the problem would be solved. I'm having trouble with how I'd actually do any of this.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>